/**
 * @file    data.h
 * @brief   数据接口
 * @details This is the detail description.
 * @author  wang-haoyu
 * @date    2025年7月10日 (created)
 * @version 0.0.1
 * @par Copyright (C):
 *          All Rights Reserved.
 * @par Encoding:
 *          UTF-8
 * @par Description        :
 * 1. Hardware Descriptions:
 *      None.
 * 2. Program Architecture:
 *      None.
 * 3. File Usage:
 *      None.
 * 4. Limitations:
 *      None.
 * 5. Else:
 *      None.
 * @par Modification:
 * -# Date          : 2025年7月10日;
 * Revision         : 0.0.1;
 * Author           : wang-haoyu;
 * Contents         :
 */
 
/* =============================================================================
 *                                header files
 * ========================================================================== */
#ifndef __DATA_H
#define __DATA_H
#include "jm_config.h"

/* =============================================================================
 *                              macros & constants
 * ========================================================================== */
#define HALF_CIRCLE 3.1415926535f
#define SINGLE_CIRCLE  6.283185307f

#define LIMIT_VALUE(x, min_limit, max_limit) \
    ( ((x) < (min_limit)) ? (min_limit) : ( (x) > (max_limit) ? (max_limit) : (x) ) )

#define RAD_TO_ANGLE(_RAD) (_RAD*180.0f/3.1415926535f)	
#define ANGLE_TO_RAD(_ANGLE) (_ANGLE/(180.0f/3.1415926535f))	
/* =============================================================================
 *                          data structure definitions
 * ========================================================================== */

//关节电机数据解析参数
typedef struct 
{
    float jm_pos_min;   //位置最小值
    float jm_pos_max;   //位置最大值
    float jm_vel_min;   //速度最小值
    float jm_vel_max;   //速度最大值
    float jm_tor_min;   //力矩最小值
    float jm_tor_max;   //力矩最小值
}jm_data_analys_param_t;

//关节电机过程控制参数
typedef struct 
{
    float motor_pos_des;        //关节电机位置设置
	rt_uint16_t motor_vel_des;  //关节电机速度设置
	rt_uint16_t motor_i_des;    //关节电机力矩设置
}jm_ctrl_param_t;

//关节电机基础控制参数
typedef struct 
{
    float pos_wave_thr;         //位置波动阈值
	float speed_wave_thr;       //速度波动阈值
    float zero_point_pos;       //零点校准找硬限位极限位置设置
    rt_uint16_t zero_point_vel; //零点校准速度设置
	rt_uint16_t zero_point_tor; //零点校准力矩设置
    rt_uint16_t normal_run_tor; //正常运行时力矩设置
}jm_base_ctrl_param_t;


//关节电机数据获取
typedef struct 
{
    bool connect_sta;			    //连接状态
	bool enable_sta; 			    //电机使能状态
    rt_uint8_t motor_sta_word;	    //电机状态码
	int motor_id;				    //电机ID号
	float motor_pos;			    //电机的位置信息
	float motor_vel;			    //电机的速度信息
	float motor_torque;			    //电机的扭矩信息
	float motor_mos_tempreture;	    //驱动上 MOS 的平均温度
	float motor_rotor_tempreture;   //电机内部线圈的平均温度
}jm_drv_info_get_t;


/**********达妙4310关节电机解析参数-start***********/
#define JM_POS_MIN_DAMIAO_4310       -12.5f
#define JM_POS_MAX_DAMIAO_4310       12.5f
#define JM_VEL_MIN_DAMIAO_4310       -30.0f
#define JM_VEL_MAX_DAMIAO_4310       30.0f
#define JM_TOR_MIN_DAMIAO_4310       -10.0f
#define JM_TOR_MAX_DAMIAO_4310       10.0f
/**********达妙4310关节电机解析参数-end***********/

/**********达妙4340关节电机解析参数-start***********/
#define JM_POS_MIN_DAMIAO_4340       -62.5f
#define JM_POS_MAX_DAMIAO_4340       62.5f
#define JM_VEL_MIN_DAMIAO_4340       -30.0f
#define JM_VEL_MAX_DAMIAO_4340       30.0f
#define JM_TOR_MIN_DAMIAO_4340       -30.0f
#define JM_TOR_MAX_DAMIAO_4340       30.0f
/**********达妙4340关节电机解析参数-end***********/

/**********达妙4310关节电机基础控制参数-start***********/
#define JM_BC_POS_WAVE_THR_DAMIAO_4310      0.02f
#define JM_BC_VEL_WAVE_THR_DAMIAO_4310      0.01f
#define JM_BC_ZERO_POINT_POS_DAMIAO_4310    12.5f
#define JM_BC_ZERO_POINT_VEL_DAMIAO_4310    100
#define JM_BC_ZERO_POINT_TOR_DAMIAO_4310    1000
#define JM_BC_NORMAL_RUN_TOR_DAMIAO_4310    10000
/**********达妙4310关节电机基础控制参数-end***********/

/**********达妙4340关节电机基础控制参数-start***********/
#define JM_BC_POS_WAVE_THR_DAMIAO_4340      0.02f
#define JM_BC_VEL_WAVE_THR_DAMIAO_4340      0.01f
#define JM_BC_ZERO_POINT_POS_DAMIAO_4340    62.5f
#define JM_BC_ZERO_POINT_VEL_DAMIAO_4340    400
#define JM_BC_ZERO_POINT_TOR_DAMIAO_4340    1000
#define JM_BC_NORMAL_RUN_TOR_DAMIAO_4340    10000
/**********达妙4340关节电机基础控制参数-end***********/

//关节电机解析参数宏定义
#define JM_DRV_DATA_ANALYS_INITALIZER(MOTOR_TYPE) (jm_data_analys_param_t){\
    JM_POS_MIN_ ## MOTOR_TYPE,\
    JM_POS_MAX_ ## MOTOR_TYPE,\
    JM_VEL_MIN_ ## MOTOR_TYPE,\
    JM_VEL_MAX_ ## MOTOR_TYPE,\
    JM_TOR_MIN_ ## MOTOR_TYPE,\
    JM_TOR_MAX_ ## MOTOR_TYPE\
}

//关节电机控制参数宏定义
#define JM_DRV_BASE_CTRL_INITALIZER(MOTOR_TYPE) (jm_base_ctrl_param_t){   \
    JM_BC_POS_WAVE_THR_ ## MOTOR_TYPE,              \
    JM_BC_VEL_WAVE_THR_ ## MOTOR_TYPE,              \
    JM_BC_ZERO_POINT_POS_ ## MOTOR_TYPE,            \
    JM_BC_ZERO_POINT_VEL_ ## MOTOR_TYPE,            \
    JM_BC_ZERO_POINT_TOR_ ## MOTOR_TYPE,            \
    JM_BC_NORMAL_RUN_TOR_ ## MOTOR_TYPE,            \
}
/* =============================================================================
 *                         static variable definitions
 * ========================================================================== */

/* =============================================================================
 *                         static function definitions
 * ========================================================================== */

/* =============================================================================
 *                         global function definitions
 * ========================================================================== */

#endif
/*******************************************************************************
 *                                  EOF
 ******************************************************************************/